package com.sumu.today.models.permission.config;

import com.sumu.today.models.permission.commons.LoginInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author sumu
 * @date 12/15/2021 9:06 PM
 */
@Slf4j
@Configuration
public class MyConfig implements WebMvcConfigurer {


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        log.info("注册拦截器");
        registry.addInterceptor(new LoginInterceptor()).addPathPatterns("/**") //拦截所有请求，包括静态资源文件
                .excludePathPatterns("/", "/permission/user/register","**/login","/permission/login", "/index.html",
                        "/permission/kaptcha/**","/user/login", "/css/**", "/images/**", "/js/**", "/fonts/**"); //放行登录页，登陆操作，静态资源
    }

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        //当访问 “/” 或 “/index.html” 时，都直接跳转到登陆页面
        registry.addViewController("/").setViewName("permission/login.html");
        registry.addViewController("/index.html").setViewName("permission/login.html");
        //添加视图映射 main.html 指向  dashboard.html
        registry.addViewController("/main.html").setViewName("permission/login.html");
    }
}
